var app = angular.module("myrelease",[]);//goods_detail
var uid ,id,cur_page = 1;
var noteRes = [],goodsRes = [],noMore = false;
app.controller("myreleasecontroller",function($scope,$http){
	$scope.initView = function(){
		if(noMore){return};
	plus.nativeUI.showWaiting("加载中...");
	$http({
		method:'post',
		url:apiRoot,
		data:{
			action:'Trade.myGoods',
			uid:uid,
			page:cur_page
		} 
	}).then(function successCallback(response){
        plus.nativeUI.closeWaiting();
        if(response.data.data == undefined){
        	$scope.not_more = 1;
        	noMore = true;
        	return; 
        }
        goodsRes.push(response.data.data);
		$scope.goods = goodsRes;
		console.log(JSON.stringify($scope.goods)); 
		
	},function errorfunction(e){
		plus.nativeUI.closeWaiting();
		console.log(e);
	})
} 
	$scope.neirxiangq = function(){ 
		if(noMore){return}
		plus.nativeUI.showWaiting('加载中...');
		$http({
		method:'post',
		url:apiRoot,
		data:{
			action:'Community.myNote',
			uid:uid,
			page:cur_page
		}
		}).then(function successCallback(response){
			plus.nativeUI.closeWaiting();
			if(response.data.data == undefined){
	        	$scope.not_more = 1;
	        	noMore = true;
	        	return; 
	        }
			noteRes.push(response.data.data);
	        $scope.mynote = noteRes;
	        console.log(JSON.stringify($scope.mynote));
		},function errorfunction(e){
			plus.nativeUI.closeWaiting();
			console.log(e);
		})
		
	}
	$scope.detailes = function(spage,uid,type,id){ 
		//跳内容详情
		if (spage == 'view_detail.html'){
			openPage(spage,{my:'my',noteUid:uid,type:type,noteId:id});
		} else if(spage == 'goods_detail.html') {
			openPage(spage,{my:'my',gUid:uid,type:type,gId:id});
		}
	}
	$scope.noteupdate = function(id){                      
		// 删除动态   弹出提示信息对话框
		plus.nativeUI.confirm( "删除后将不可查看！你确定要删除吗?", function(e){
			if(e.index==0){
				$http({
					method:'post',
					url:apiRoot,
					data:{
						action:'Community.note_updeta',
						id:id,
						uid:uid  
					}
					}).then(function successCallback(response){
						toast('删除成功！');
						$scope.neirxiangq(uid);
					},function errorfunction(e){
						console.log(JSON.stringify(e));
					})
			}else{
				setTimeout(function() {
					$.swipeoutClose(li);
				}, 0);
			} 
		}, "去卖艺", ["确定","取消"] );
	}
	$scope.goodsupdate = function(type,id){                      
		if(type == '0'){           //商品确认已售
			var title = "确定删除吗？";
		}else if(type == '2'){     //商品下架
			var title = "已售商品用户可查看但不可购买，确定已售？";
		}else if(type == '3'){		//商品删除
			var title = "下架后用户将无法查看商品，确定下架？";
		}
		// 删除动态   弹出提示信息对话框
		plus.nativeUI.confirm( title, function(e){
			if(e.index==0){
				$http({
					method:'post',
					url:apiRoot,
					data:{
						action:'Trade.mygoodsupdate',
						id:id,
						uid:uid,
						status:type,
					}
					}).then(function successCallback(response){
						console.log(JSON.stringify(response));
						toast(response.data.data.data);
						$scope.initView(uid);
				//		console.log(JSON.stringify(response.data.data.note));
					},function errorfunction(e){
						toast(response.data.data.desc)
						console.log(e);
					})
			}else{
				setTimeout(function() {
					$.swipeoutClose(li);
				}, 0);
			} 
		}, "去卖艺", ["确定","取消"] );
	}
	
})  


document.addEventListener("plusready",function(){
	appElement=document.querySelector('[ng-controller=myreleasecontroller]');
	$scope= angular.element(appElement).scope();
	uid = plus.storage.getItem('uid');
	var is_first = true;
	if(is_first){
		$scope.neirxiangq();
		is_first = false;
	}
	$('#note').on('tap',function(){
		cur_page = 1;
		noMore = false;
		noteRes = [];
		goodsRes = [];
		$scope.not_more = 0;
		$scope.neirxiangq();
	})
	$('#bussiness').on("tap",function(){
		cur_page = 1;
		noMore = false;
		noteRes = [];
		goodsRes = [];
		$scope.not_more = 0;
		$scope.initView();
	})	
	$scope.$apply();
})
